<?php

include_once '../@base/portal.php';
include_once '../login/login.php';

$user = $post->user;
$params=$post->params;
$login = login($user->number, $user->passwd);
if ($login['status'] == 0 && $login['userbase']['level'] > 0) {
  output(doQuery($params));
} else {
  output(['status' => 1]);
}

function doQuery($params) {
  $sql = "SELECT name,value FROM oprec_config_params ORDER BY name ASC";
  if($params && count($params)>0){
    $params_names="('".implode("','",$params)."')";
    $sql="SELECT name,value FROM oprec_config_params WHERE name IN {$params_names} ORDER BY name ASC";
  }
  logfile('load_param', $sql);
  $result = exec_sql($sql);
  if ($result) {
    $res = array();
    foreach ($result as $cell) {
      $res[$cell['name']] = json_decode($cell['value']);
    }
    return [
      'status' => 0,
      'params' => $res,
    ];
  } else {
    return ['status' => 2];
  }
}
